// pages/home/home.js
import {
    lgRequest
} from '../../utils/ajax'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        statusBarHeight: getApp().globalData.statusBarHeight,
        titleBarHeight: getApp().globalData.titleBarHeight,
        sysInfo: getApp().globalData.sysInfo,
        isIphoneX: getApp().globalData.isIphoneX,
        userInfo: wx.getStorageSync('userInfo'),
        leftImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/a68f960714ef916f5dd6960a99fbab78.png',
        centerImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/4f1c54d957720b5aa4d65a9e0a93e75e.png',
        rightImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/90da806b7328cefb1c5f9a865ada32b2.png',
        contentImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/a947c26b441afbc63b1bb682f7981928.png',
        orderImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/cb19bae694d6fbc1dea15023e538206c.png',
        positionImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/9264ebd2b29d48393bc42933b76b8790.png',
        toHandleImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/d75401a8e782b01eebab544b39586b33.png',
        nextPre: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/45854bf8c71088dc4f3379aadc3f0865.png',
        beforePre: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/f727a15b92a53e4d259ac6a24e7f5074.png',
        refreshImg: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/15/16abf76258b39c23c78c2db3d490d627.png',
        listAccount: 0,
        undoneInfoList: [],
        params: {},
        urgant: [{
                type: '即刻',
                id: 0
            },
            {
                type: '优先',
                id: 1
            },
            {
                type: '常规',
                id: 2
            },
            {
                type: '暂存',
                id: 3
            },

        ],
        shouyeList: [],
        isNavshow: true,
        showOrderFlow: false,
        showFailureBypass: false,


        photerIcon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/ca4a458299232ae12fd7f07cae307ba5.png",
        shangChuang: 'http://114.115.190.196:8082/profile/upload/2022/09/13/53ead76e72a504af6130b526634bf9a2.png',
        delectImgTag: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/19/713a49f43240fae4d44090d92d7f9cf6.png",
        workList: "",
        orderList: "",
        problemType: "",
        fileList: [],
        showFailureBypass: false,
        params: {},
        remark: '',
        showOrderFlow: false,
        overPeople: "",
        orderType: [{
                problemType: "集成",
                typeCode: 1
            },
            {
                problemType: "设备",
                typeCode: 2
            },
            {
                problemType: "网络",
                typeCode: 3
            },
            {
                problemType: "电力",
                typeCode: 4
            },
        ],
        isType: 0,
        problemType: [],
        showkuaidu: false,
        switchListOne: [{
                name: "政府施工",
                name_active: "政府施工",
                isSelect: false,
                nameDetail: "政府施工",
                id: ''
            },
            {
                name: "不可抗力",
                name_active: "不可抗力",
                isSelect: false,
                nameDetail: "不可抗力",
                id: ''
            },
            {
                name: "其他",
                name_active: "其他",
                isSelect: false,
                nameDetail: "其他",
                id: ''
            },
        ],
        whiteBg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/f37e1fe6501f44eb5fb877eff35068f2.png",
        redBg: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/9b362108a7b3d67529486e7bb8967388.png",
        circle: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/ac0b6544db4ed907bf5444fc888409aa.png",
        latitude:'',
        longitude:'',
        kuaisuList:[]
    },
    // 展开收缩
    toggleNav() {
        this.setData({
            isNavshow: !this.data.isNavshow
        })
    },
    // 跳转站点详情
    goZhan(e){
        console.log(e.currentTarget.dataset.item);
        let zhanInfo = JSON.stringify(e.currentTarget.dataset.item);
        console.log(zhanInfo);
        wx.navigateTo({
        //   url: `../stateDetail/stateDetail?zhanIdInfo=${zhanInfo}`,
          url: `../minePage/stateDetail/stateDetail?zhanIdInfo=${zhanInfo}`,
        })
    },

    showOrderFlow(e) {
        // console.log(e);
        this.data.params.wid = e.currentTarget.dataset.item.wid
        this.setData({
            showOrderFlow: true
        })
    },
    // 组内流转
    Goliuzhuan(e) {
        // console.log(e.currentTarget.dataset.item.nickName);
        let params = {
            conductor: e.currentTarget.dataset.item.userId,
            wId: this.data.undoneInfoList.wid
        }
        console.log(params);
        lgRequest("zuneiliuzhuan", params, {
            doSuccess: res => {
                console.log(res);
                this.setData({
                    showOrderFlowOne: false
                })
                wx.showToast({
                    title: '修改成功!',
                })
            }
        })
    },
    // 获取工单详情
    getWorkList() {
        let params = {
            zId: this.data.undoneInfoList.zid
        }
        lgRequest("getWorkList", params, {
            doSuccess: (r) => {
                // console.log(r)
                this.setData({
                    workList: r.data
                })
            }
        })
    },
    // 获取问题列表
    getOrderList() {
        let params = {
            zId: this.data.undoneInfoList.zid
        }
        lgRequest("dList", params, {
            doSuccess: (r) => {
                console.log(r)
                let orderList = r.data;

                // if(orderList.over){
                orderList.forEach(item => {
                    item.content = item.content.replace("null", '')
                    // let arr = [];
                    item.pic = (item.over || '').split(',')
                    // item.over = arr
                    console.log('item.pic', item.pic)
                })
                // }

                this.setData({
                    orderList: orderList
                })
            }
        })
    },
    //获取问题类型
    getProblem() {
        let serve = getApp().globalData.server;
        let Authorization = getApp().globalData.Authorization
        wx.request({
            url: `${serve}server/dictionaries/problem_type`,
            header: {
                Authorization
            },
            success: (r) => {
                console.log(r)
                this.setData({
                    problemType: r.data.data
                })
            }
        })
    },
    // 获取暂不处理原因
    noProcessing() {
        let params = {
            code: "failure_bypass"
        }
        lgRequest("dictionaries", params, {
            doSuccess: r => {
                console.log(r)
                this.setData({
                    noProcessing: r.data
                })
            }
        })
    },
    // 暂不处理说明
    getFailureBypassRemark(e) {
        console.log(e.detail.value)
        this.data.params.remark = e.detail.value
        console.log(this.data.params.remark)
    },
    // 得得得得得的额
    overPeople() {
        let params = {
            // code: "group"
            zhanId: this.data.undoneInfoList.zid

        }
        lgRequest("userList1", params, {
            doSuccess: r => {
                console.log(r)
                let overPeople = r.data
                overPeople.forEach(item => {
                    item.value = item.userId;
                    item.text = item.roleName;
                })
                this.setData({
                    overPeople

                })
            }
        })
    },
    // 选择流转人
    selectPeople(e) {
        console.log(e)
        let selectPeople = e.currentTarget.dataset.item.nickName;
        this.data.params.conductor = e.currentTarget.dataset.item.userId;
        this.setData({
            selectPeople
        })
        this.onCloseC();
    },
    // 选择问题
    selectType(e) {
        console.log(e)
        let isType = e.currentTarget.dataset.index;
        let typeCode = e.currentTarget.dataset.typeCode;

        this.setData({
            isType
        })

    },
    // 获取工单流转问题标签
    getProblemTag() {
        let params = {
            code: "problem_type",
        }
        lgRequest("dictionaries", params, {
            doSuccess: r => {
                console.log(r);
                this.setData({
                    problemTag: r.data,
                })
            }
        })
    },
    // 选择工单流转问题
    selectproblemTag(e) {

        console.log(e)
        let item = e.currentTarget.dataset.item
        let index = e.currentTarget.dataset.index
        let problemTag = this.data.problemTag;

        this.data.problemType.push(item.valueId)
        console.log(this.data.problemType)
        problemTag[index].is = !problemTag[index].is
        this.data.params.problemType = this.data.problemType.toString();

        this.setData({
            problemTag
        })
    },
    // 获取流转说明
    getOrderFlow(e) {
        console.log(e.detail.value)
        this.data.params.mvremark = e.detail.value
    },
    // 提交工单流转信息
    submitOrderFlow() {
        this.data.params.dqGps = this.data.workList.gps;
        let params = this.data.params;
        lgRequest("submitOrderFlow", params, {
            doSuccess: r => {
                console.log(r)
                this.getOrderList(); //获取工单列表
                this.onClose();
            }
        })

    },
    showOrderCompletion(e) {
        this.data.params.wid = e.currentTarget.dataset.item.wid
        this.setData({
            showOrderCompletion: true
        })
    },
    // 转到历史工单

    toHistory() {
        // debugger
        let info = encodeURIComponent(JSON.stringify(this.data.undoneInfoList));
        wx.navigateTo({
            url: `../historyWorkList/historyWorkList?info=${info}`,
            fail: err => {
                console.log(err)
            }
        })
    },
    // 转到流转记录
    totransfer(e) {
        // let info = e.currentTarget.dataset.item
        let info = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
        wx.navigateTo({
            url: `/pages/minePage/transferRecord/transferRecord?info=${info}`,
            fail: err => {
                console.log(err)
            }
        })
    },
    // 展示暂不处理
    showFailureBypass(e) {
        console.log(e)
        this.data.params.wid = e.currentTarget.dataset.item.wid;
        this.setData({
            showFailureBypass: true
        })

    },
    showPic(e) {
        this.setData({
            showPic: true,
            itemPic: e.currentTarget.dataset.item,
        })
    },
    wd() {
        let a = "2153nulldw"
        // a=a.substring(a.indexOf("n"),a.indexOf("n")+3)
        a = a.replace("null", '')
        console.log('去掉null', a);
        var obj = {}
        // element.list.map((item,index)=>{
        // // console.log('我是list',element.list)
        //   console.log('我是list',item)
        //   item=item.split("_")
        // console.log('我是list',item)
        //  obj[index] = item
        //         })
        // wx.showToast({
        //   title: '提交中请稍后',
        //   icon:'loading'
        // })
        // wx.showLoading({
        //   title:'提交中请稍后'
        // })

    },
    getLocation() {
        wx.getLocation({

            success: (result) => {
                this.setData({
                    latitude: result.latitude,
                    longitude: result.longitude,
                })
                this.undoneList()
            },
            fail: (res) => {},
            complete: (res) => {},
        })
    },


    toTaskPatrol() {

    },
    toOtherPage(e) {
        let type = e.currentTarget.dataset.type
        switch (type) {
            case '0':
                wx.navigateTo({
                    url: '../minePage/taskPatrol/taskPatrol',
                })
                break;
            case '1':
                wx.navigateTo({
                    url: '../minePage/freePatrol/freePatrol',
                })
                break;
            case '2':
                wx.navigateTo({
                    url: '../minePage/patrolRecord/patrolRecord',
                })
            case '3':
                this.setData({
                    showkuaidu: true,
                })
                this.dingwei()
                break;
        }
    },
    minList(){
        let params = {
          name:this.data.name
        }
        lgRequest('minList', params, {
          // errAlert: false,
          doSuccess: r => {
            if (r.code == 200) {
              
              this.setData({
                searchList:r.data
              })
            } else {
              // wx.showToast({
              //   title: '附近无站点',
              //   icon: 'none'
              // })
            }
          },
          doComplete: r => {
          }
        })
      },
      getnearby(){
        // wx.showLoading({
        //   title:'加载中'
        // })
        let params = {
          overGps : this.data.latitude+","+this.data.longitude
          // overGps : "39.534958,116.720041"
        }
        console.log(params)
        lgRequest("getnearby",params,{
          doSuccess:r=>{
            console.log(r)
            wx.hideLoading()
            if(r.data.length>=1){
              let getnearby = r.data
              let list = []
              getnearby.forEach(element => {
                let arr = []
                
                arr =element.gps.split(",");
                console.log("arr",arr)
                let a = this.getDistance(arr[1],arr[0],this.data.latitude,this.data.longitude)
                // let a = this.getDistance(arr[1],arr[0],39.534958,116.720041)
                console.log(a)
                element.conds=a
                
            
      
              });
              getnearby.sort(function(a,b){
                return a.conds - b.conds;
              })
              this.setData({
                getnearby
              })
            }else {
              wx.showToast({
                title: '附近无站点',
                icon: 'none'
              })
            }
          }
        })
      },
      Rad(d){
        return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
      },
      getDistance(lat1,lng1,lat2,lng2){
        var radLat1 = lat1* Math.PI / 180.0;
        var radLat2 = lat2* Math.PI / 180.0;
        var a = radLat1 - radLat2;
        var  b = lng1* Math.PI / 180.0 - lng2* Math.PI / 180.0;
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
        Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
        s = s *6378.137 ;// EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000; //输出为公里
        //s=s.toFixed(2);
        return s;
      },
    // 快速定位
    dingwei(){
        let params = {
            overGps : this.data.latitude+","+this.data.longitude
            // overGps : "39.534958,116.720041"
          }
          console.log(params);
        lgRequest("kuaisu", params, {
            doSuccess: (r) => {
                console.log("r", r)
                this.setData({
                    kuaisuList:r.data
                })
            }
        }) 
    },
    toCreateOrder() {
        wx.navigateTo({
            url: '../minePage/createOrder/createOrder',
        })
    },
    // 计算距离
    Rad(d) {
        return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
    },
    getDistance(lat1, lng1, lat2, lng2) {
        var radLat1 = lat1 * Math.PI / 180.0;
        var radLat2 = lat2 * Math.PI / 180.0;
        var a = radLat1 - radLat2;
        var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
            Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378.137; // EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000; //输出为公里
        //s=s.toFixed(2);
        return s;
    },
    //获取任务巡查数量
    listSum() {
        let params = {
            executor: this.data.userInfo.userId,
        }
        lgRequest('listSum', params, {
            errAlert: false,
            doSuccess: r => {
                if (r.code == 200) {
                    this.setData({
                        listAccount: r.data.sum
                    })
                } else {
                    wx.showToast({
                        title: r.msg,
                        icon: 'none'
                    })
                }
            },
            doComplete: r => {}
        })
    },
    // 未完成工单
    getNowork() {
        let userId1 = this.data.undoneInfoList.zid
        // console.log(this.data.undoneInfoList);
        wx.request({
            url: `https://www.mengbaoonline.com:8182/server/workOther/unWorkSite/${userId1}`,
            method: 'GET',
            dataType: 'json',
            header: {
                'content-type': 'application/json',
                'Authorization': wx.getStorageSync('token'),
                // 'headerUserId': user.id,
                // 'headerUserToken': user.userToken
            },
            success: (res) => {
                console.log(res, '未完成工单')
            },
        });
    },
    //获取待处理工单列表
    undoneList() {
        let params = {
            conductor: this.data.userInfo.userId
        }
        lgRequest('undoneList', params, {
            errAlert: false,
            doSuccess: r => {
                // if (r.code == 200) {
                //   let undoneInfoList = r.data
                //   let list = []
                //   undoneInfoList.forEach(element => {
                //     let arr = []
                //     element.list = element.list.replace("null", '')
                //     arr = element.gps.split(",");
                //     console.log("arr", arr)
                //     let a = this.getDistance(arr[1], arr[0], this.data.latitude, this.data.longitude)
                //     console.log(a)
                //     element.conds = a
                //     list = element.list.split("#")
                //     element.list = list;
                //     let newList = []
                //     element.newList = []

                //     element.list.map((item, index) => {
                //       var obj = {}
                //       // console.log('我是list',element.list)
                //       console.log('我是list', item)
                //       item = item.split("_")
                //       // console.log('我是list',item)
                //       // obj[index] = item
                //       item.forEach((item1, index1) => {
                //         obj[index1] = item1
                //         console.log(item1)
                //       })
                //       console.log(obj)
                //       newList.push(obj)
                //       console.log("我是newList", newList)
                //       element.newList.push(obj)
                //     })
                //   });
                //   // setTimeout(()=>{
                //   //   this.getNowork()
                //   // },2000)

                //   this.setData({
                //     undoneInfoList
                //   })
                //   this.getListOfList()
                // } else {
                //   wx.showToast({
                //     title: r.msg,
                //     icon: 'none'
                //   })
                // }
                // console.log(r.data,'kaishi');
                r.data.map((item) => {
                    // console.log(11111);
                    if (item.mvpic == null) {
                        return
                    } else {
                        //  console.log(item.mvpic.split(","));
                        item.mvpic = item.mvpic.split(",")
                    }
                    if (item.mvTime == null) {
                        item.mvTime = '暂无'
                    }
                    if (item.lastConductor == null) {
                        item.lastConductor = '暂无'
                    }
                    if (item.content == null) {
                        item.content = '暂无'
                    }
                    if (item.repairData == 1) {
                        item.repairData = '首'
                        // console.log(item,'1111');
                        return
                    } else {
                        //  console.log(222);
                    }
                    return

                })


                this.setData({
                    undoneInfoList: r.data
                })
            },
            doComplete: r => {}
        })

    },
    getListOfList() {
        // let undoneInfoList = this.data.undoneInfoList;
        let list = this.data.undoneInfoList[0].list;
        console.log(list)
        list.forEach(r => {
            r = r.split("_")
            console.log(r)
        })
        console.log(list)
        this.data.undoneInfoList[0].list = list
    },
    // 跳转工单详情
    toOrderDetails(e) {
        console.log("页面传参", e);
        let info = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
        wx.navigateTo({
            url: `../minePage/toOrderDetails/toOrderDetails?info=${info}`,
        })
    },
    // 首页动态维护数据
    getshouye() {
        lgRequest('shouyeweihu', {}, {
            doSuccess: r => {
                console.log(r, '首页动态维护数据')
                r.data.map((item) => {
                    if (item.createBy == null) {
                        item.createBy = "暂无"
                    }
                    item.createTime = item.createTime.slice(10, 16)
                })
                this.setData({
                    shouyeList: r.data
                })
            }
        })
    },
    // 关闭弹窗
    onClose() {
        let noProcessing = this.data.noProcessing;
        noProcessing.forEach(r => {
            r.is = false
        })
        let problemTag = this.data.problemTag;
        problemTag.forEach(r => {
            r.is = false
        })
        let params = {
            problemType: ''
        }
        this.setData({
            showFailureBypass: false,
            noProcessing,
            params,
            remark: "",
            showOrderFlow: false,
            showOrderCompletion: false,
            selectPeople: '',
            problemTag,
            problemType: '',
            showOrderFlowOne: false,
            showPic: false,
            isShetingShow: false,
            showkuaidu: false,
        })
    },
    // 站点停用确认
    ZhanTingQ(e) {
        let index = e.currentTarget.dataset.index;
        let switchListOne = this.data.switchListOne;
        // switchListOne[index].value = switchListOne[index].value == 1 ? "0" : "1";
        let selectSwitchItem = e.currentTarget.dataset.item;
        this.setData({
            switchListOne,
            selectSwitchItem,
        });
        let params = {
            // id: this.data.switchListOne.id,
            // value: [this.data.switchListOne[0].value, this.data.switchListOne[1].value, this.data.switchListOne[2].value],
            endTime: this.data.endTime,
            remark: this.data.remark,
            // content: [this.data.switchListOne[0].name, this.data.switchListOne[1].name, this.data.switchListOne[2].name],
            state: 6,
            siteId: this.data.undoneInfoList.zid,
            url: this.data.url
        };
        console.log(params, 'params');
        lgRequest("zhandiantingyon", params, {
            doSuccess: (r) => {
                // console.log("修改成功", r)
                this.setData({
                    isShetingShow: false
                })
                wx.showToast({
                    title: '修改成功',
                })
            }
        })
    },
    selectItemSwitchOne(e) {
        let index = e.currentTarget.dataset.index;
        let switchListOne = this.data.switchListOne;
        switchListOne[index].value = switchListOne[index].value == 1 ? "0" : "1";
        let selectSwitchItem = e.currentTarget.dataset.item;
        this.setData({
            switchListOne,
            selectSwitchItem,
        });
        console.log("状态按钮传参", e.currentTarget.dataset)
        let params = {
            id: this.data.switchListOne[index].id,
            value: this.data.switchListOne[index].value,
        };
        lgRequest("zhandiantingyon", params, {
            doSuccess: (r) => {
                console.log("修改成功", r)
            }
        })
    },
    showOrderFlowOne() {
        // let principalOne = wx.getStorage({
        //   key:'userInfo',
        //   success:function(res){
        //     var principal = res.data.userGroup
        //     // return principal
        //     console.log(principal);

        //   }
        // })
        // console.log(principalOne);
        const Cates = wx.getStorageSync("userInfo");
        let principal = Cates.userId
        console.log(principal, 'Cates');
        wx.request({
            url: `https://www.mengbaoonline.com:8182/server/workOther/userGroup/${principal}`,
            method: 'GET',
            dataType: 'json',
            header: {
                'content-type': 'application/json',
                'Authorization': wx.getStorageSync('token'),
                // 'headerUserId': user.id,
                // 'headerUserToken': user.userToken
            },
            success: (res) => {
                console.log(res.data.data, 'res');
                this.setData({
                    liuzhuanList: res.data.data
                })
            },
        });
        this.setData({
            showOrderFlowOne: true
        })
    },
    // 设备拆除
    Schaichu() {
        let params = {
            zId: this.data.undoneInfoList.zid,
            state: 5
        }
        lgRequest("shebeichaichu", params, {
            doSuccess: (r) => {
                // console.log("修改成功", r)
                wx.showToast({
                    title: '修改成功',
                })
            }
        })
    },
    sheting() {
        let params = {
            siteId: this.data.undoneInfoList.zid
        }
        // switchListOne = this.data.switchListOne
        lgRequest('zhandiantingyonjilu', params, {
            doSuccess: r => {
                console.log(r, '站点停用变更记录')
                r.data.map((item) => {
                    this.data.switchListOne.id = item.id
                    // console.log(this.data.switchListOne.id,'this.data.switchListOne');
                    return
                })
                this.setData({
                    zhanTingList: r.data,
                })
            }
        })
        this.setData({
            isShetingShow: true,
        })
    },
    // 暂不处理原因
    selectFailureBypass(e) {
        let index = e.currentTarget.dataset.index;
        let item = e.currentTarget.dataset.item;
        let params = this.data.params;
        params.failureBypass = item.valueId;
        params.state = 4;
        this.setData({
            params
        })


        console.log(e)
        let noProcessing = this.data.noProcessing;
        noProcessing[index].is = !noProcessing[index].is
        this.setData({
            noProcessing
        })
    },
    submitFailureBypass() {
        let params = this.data.params
        lgRequest("smbitQuestionPic", params, {
            doSuccess: r => {
                console.log(r)
                this.getOrderList(); //获取工单列表
                this.onClose();

            }
        })
    },
    // 展示流转人
    showPeople() {
        this.setData({
            showPeople: true
        })
    },
    // 选择问题
    selectType(e) {
        console.log(e)
        let isType = e.currentTarget.dataset.index;
        let typeCode = e.currentTarget.dataset.typeCode;

        this.setData({
            isType
        })

    },
    // 选择工单流转问题
    selectproblemTag(e) {

        console.log(e)
        let item = e.currentTarget.dataset.item
        let index = e.currentTarget.dataset.index
        let problemTag = this.data.problemTag;

        this.data.problemType.push(item.valueId)
        console.log(this.data.problemType)
        problemTag[index].is = !problemTag[index].is
        this.data.params.problemType = this.data.problemType.toString();

        this.setData({
            problemTag
        })
    },
    //上传图片
    afterRead(event) {
        let that = this;
        console.log(event)
        const {
            file
        } = event.detail;
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        let url = getApp().globalData.obLineSever + "server/picState";
        file.forEach((itemFile) => {

            wx.uploadFile({
                // url: "http://114.115.190.196:8082/common/upload",
                // url:"https://www.mingchuliangzao.com.cn:8632/common/upload",
                url: "https://www.mengbaoonline.com:8182/common/upload",
                filePath: itemFile.path,
                name: "file",
                formData: {
                    user: "test"
                },
                header: {
                    "Content-Type": "multipart/form-data",
                    Authorization: getApp().globalData.Authorization,
                },
                success: (res) => {
                    // 上传完成需要更新 fileList 
                    let data = JSON.parse(res.data);
                    console.log(res)
                    wx.showToast({
                        title: "上传成功！",
                    });
                    let params = {
                        siteId: that.data.zhanIdInfo.id,
                        state: that.data.selectIndexType + 1,
                        pic: data.url,
                    }
                    lgRequest("addPicState", params, {
                        doSuccess: (res) => {
                            // console.log(res)
                            if (res.code == 200) {
                                console.log(res, );
                                this.picStateList()
                            }
                        }

                    })


                },
                fail(error) {
                    wx.showToast({
                        title: "上传失败",
                    });
                    console.log(error, '这是上传图片的错误')
                },
            });

            console.log(itemFile)

            // wx.uploadFile({
            //   url: "https://www.mingchuliangzao.com.cn:8632/common/upload",
            //   filePath: itemFile.path,
            //   name: "file",
            //   formData: {
            //     user: "test"
            //   },
            //   success(res) {
            //     // 上传完成需要更新 fileList
            //     let data = JSON.parse(res.data);
            //     let obj = {
            //       pic: data.url,
            //     };
            //     let picStateInfoList = that.data.picStateInfoList;
            //     picStateInfoList.unshift(obj);
            //     that.setData({
            //       picStateInfoList,
            //     });
            //   },
            //   fail(error) {
            //     wx.showToast({
            //       title: "上传失败，请稍后再试！",
            //     });
            //   },
            // });
        });
    },
    // 提交工单流转信息
    submitOrderFlow() {
        this.data.params.dqGps = this.data.workList.gps;
        let params = this.data.params;
        lgRequest("submitOrderFlow", params, {
            doSuccess: r => {
                console.log(r)
                this.getOrderList(); //获取工单列表
                this.onClose();
            }
        })

    },
    // 关闭流转人窗口
    onCloseC() {
        this.setData({
            showPeople: false
        })
    },
    // 完成工单确定
    OrderCompletion() {
        this.data.params.zid = this.data.undoneInfoList.zid;
        this.data.params.dqGps = this.data.undoneInfoList.gps;
        this.data.params.conductor = this.data.undoneInfoList.conductor;
        this.data.params.state = 2;
        let params = this.data.params
        lgRequest("smbitQuestionPic", params, {
            doSuccess: r => {
                console.log(r)
                this.getOrderList(); //获取工单列表
                this.onClose();
            }
        })
    },
    // 跳转工单地图
    toOrderMap() {
        wx.navigateTo({
            url: `../minePage/orderMap/orderMap`,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        wx.getLocation({
          type: 'gcj02',
          success:res=> {
            const latitude = res.latitude
            const longitude = res.longitude
            let circles = []
            // let circlesItem = {
            //   latitude,
            //   longitude,
            //   fillColor:'#2BD94780',
            //   radius: 200,
            // }
            // circles.push(circlesItem)
            that.setData({
              latitude,
              longitude,
              circles
            })
            // setTimeout(()=>{
            //   this.getnearby()
            //   this.minList()
            // },500)
            
          }
        })
        // this.undoneList() //待处理工单列表
        this.getLocation() //获取当前位置
        this.getshouye()


        this.getWorkList(); //获取工单详情
        this.getOrderList(); //获取工单列表
        this.noProcessing(); //获取暂不处理原因
        this.overPeople();
        this.getProblemTag(); //获取标签列表
        // this.getProblem();//获取标签列表
        this.getZhanInfo();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.listSum()
        this.getLocation() //获取当前位置
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})